package com.simple.util;

import org.activiti.bpmn.model.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

/**
* 工作流工具类
* @author hehongfa
* @date 2021-12-29 17:40:30
*/
@Component
public class WorkflowUtil {

    /**
     * 开始任务节点
     * @return
     */
    public StartEvent createStartEvent() {
        StartEvent startEvent = new StartEvent();
        startEvent.setId("start");
        return startEvent;
    }

   /**
     * 结束任务节点
     * @return
     */
   public EndEvent createEndEvent() {
        EndEvent endEvent = new EndEvent();
        endEvent.setId("end");
        return endEvent;
    }

    /**
     *
     * @param id  对应我们画流程图中节点任务id
     * @param name 节点任务名称
     * @param assignee 任务的执行者(这一块自行决定是否添加每一环节的执行者，若是动态分配的话，可以不用传值)
     * @return
     */
    public UserTask createUserTask(String id, String name, String assignee) {
        UserTask userTask = new UserTask();
        userTask.setName(name);
        userTask.setId(id);
        userTask.setAssignee(assignee);
        return userTask;
    }

    /**
     * 排它网关
     * @param id  网关id
     * @return
     */
    protected ExclusiveGateway createExclusiveGateway(String id) {
        ExclusiveGateway exclusiveGateway = new ExclusiveGateway();
        exclusiveGateway.setId(id);
        return exclusiveGateway;
    }

    /**
     * 并行网关
     * @param id
     * @return
     */
    public ParallelGateway createParallelGateway(String id){
        ParallelGateway parallelGateway = new ParallelGateway();
        parallelGateway.setId(id);
        return parallelGateway;
    }
    /**
     *
     * @param from         连线来源节点
     * @param to        连线目标节点
     * @param name          连线名称(可不填)
     * @param conditionExpression  网关每一种线路走向的条件表达式
     * @return
     */
    public SequenceFlow createSequenceFlow(String from, String to, String name, String conditionExpression) {
        SequenceFlow flow = new SequenceFlow();
        flow.setSourceRef(from);
        flow.setTargetRef(to);
        flow.setName(name);
        if (StringUtils.isNotEmpty(conditionExpression)) {
            flow.setConditionExpression(conditionExpression);
        }
        return flow;
    }
}
